﻿namespace TomatoBreak.Web
{
    using System.Text;
    using System.Web.Mvc;

    public abstract class ApplicationController : Controller
    {
        protected virtual ActionResult HttpOk(string description = null)
        {
            return new HttpStatusCodeResult(200, description);
        }

        protected virtual ActionResult HttpCreated(string description = null)
        {
            return new HttpStatusCodeResult(201, description);
        }

        protected virtual JsonResult JsonModelStateErrors()
        {
            return Json(new { errors = ModelState.Errors() });
        }

        protected virtual JsonResult JsonCreated(object model)
        {
            return Json(model, null, null, JsonRequestBehavior.DenyGet, 201);
        }

        protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
        {
            return Json(data, contentType, contentEncoding, behavior, 200);
        }

        protected virtual JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior, int httpStatusCode)
        {
            return new JsonNetResult
                       {
                           Data = data,
                           ContentType = contentType,
                           ContentEncoding = contentEncoding,
                           JsonRequestBehavior = behavior,
                           HttpStatusCode = httpStatusCode
                       };
        }
    }
}